package com.gensdai.leliang.adapter;

import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.gensdai.leliang.R;
import com.gensdai.leliang.entity.CardCart;
import com.gensdai.leliang.remoteInterface.URLConfig;

import java.util.List;

/**
 * Created by Administrator on 2017/5/31.
 */

public class indent_in_list_adapter extends BaseAdapter {

    private List<CardCart> list_data;
    private Context mcontext;
    private Honder honder;

    public indent_in_list_adapter(Context context, List<CardCart> list) {
        mcontext = context;
        list_data = list;
    }

    @Override
    public int getCount() {
        return list_data.size();
    }

    @Override
    public Object getItem(int position) {
        return list_data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            honder = new Honder();
            convertView = LayoutInflater.from(mcontext).inflate(R.layout.indent_in_list, null);

            honder.attributeName = (TextView) convertView.findViewById(R.id.attributeName);
            honder.proName = (TextView) convertView.findViewById(R.id.proName);
            honder.cost = (TextView) convertView.findViewById(R.id.cost);
            honder.buyNum = (TextView) convertView.findViewById(R.id.number);
            honder.Indent_img = (SimpleDraweeView) convertView.findViewById(R.id.indent_img);

            convertView.setTag(honder);
        } else {
            honder = (Honder) convertView.getTag();
        }

        honder.proName.setText(list_data.get(position).getShopname());
        honder.attributeName.setText(list_data.get(position).getProductAttributeName());
        honder.cost.setText(mcontext.getString(R.string.rmb) + list_data.get(position).getPrice());
        honder.buyNum.setText(list_data.get(position).getNumber());
        if (list_data.get(position).getIc_path().length() > 5) {
            Uri uri = Uri.parse(URLConfig.BASEDOMAIN + list_data.get(position).getIc_path());
            honder.Indent_img.setImageURI(uri);
        }

        return convertView;
    }

    class Honder {

        TextView attributeName;//属性名
        SimpleDraweeView Indent_img;// 图片
        TextView buyNum;//购买数量
        TextView proName; // 商品名
        TextView cost; // 单价
    }
}
